package 网络通信1;

import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

public class Net {
	public static void main(String [] args) throws Exception
	{
		OutputStream os=new FileOutputStream("D:\\代码\\Ga\\src\\firstDemo\\test",true);
		PrintStream ps=new PrintStream(os);
		System.setOut(ps);
		//1.
		InetAddress ip=InetAddress.getLocalHost();
		System.out.println(ip.getHostName());
		System.out.println(ip.getHostAddress());
		//2.
		InetAddress ip2=InetAddress.getByName("www.baidu.com");
		System.out.println(ip2.getHostName());
		System.out.println(ip2.getHostAddress());
		boolean t=ip2.isReachable(300);
		System.out.println(t);
	}
}
